<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.title.center_zhuyonghu"></spring:message></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
       
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>健康知识家管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
             <li class="active"><a href="#">健康知识家管理</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <form id="form">
                    <div class="input">
                    <div class="textalign1">知识家名称：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="username" name="username" placeholder="知识家名称" maxlength="50" />
                    </div>
                    <div class="textalign1">标题：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="title" name="title" placeholder="标题" maxlength="25" />
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查 询</button>
                </div>
               
              </form>  
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<label id="addNew" onclick="showAddPage();" class="btn btn-default btn-sm">新 增</label>
			<label id="addNew" onclick="deleteUser();" class="btn btn-default btn-sm">删 除</label>
		</div>
		
		<!-- 新增 -->
		<div class="modal fade" id="userAdd" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h5 class="modal-title">知识家新增</h5>
					</div>
                 <form class="form-horizontal"  action="${ctx }/knowledeUser/addUser.html" id="addForm" method="post" enctype="multipart/form-data">
					<div class="modal-body">
						<div class="form-group form-group-xs">
	                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>名 称：</label>
	                        <div class="col-sm-3 text-left">
	                            <input class="form-control" id="addknowledeName" name="knowledeName" value="" placeholder="名称" type="text">
	                        </div>
	                        <label for="name" class="col-sm-3 text-right"><span class="required">*</span>标 题：</label>
	                        <div class="col-sm-3 text-left">
	                            <input class="form-control" id="addtitle" name="title"  type="text" maxlength="50"placeholder="标题">
	                        </div>
	                    </div>
	                    
	                    <div class="form-group form-group-xs">
	                        <label for="name" class="col-sm-2 text-right"><span class="required">*</span>是否置顶：</label>
	                        <div class="col-sm-3 text-left">
	                        <select class="form-control" id="addisTop" name="isTop">
	                        	<option value="0">否</option>
	                        	<option value="1">是</option>
	                        </select>
	                        </div>
	                        <label for="img" class="col-sm-3 text-right"><span class="required">*</span>图 片：</label>
	                        <div class="col-sm-3 text-left">
	                        <input type="file" class="form-control" name="img" id="img" />
	                        </div>
	                    </div>
	                    
	                    <div class="form-group form-group-xs">
	                        <label for="content" class="col-sm-2 text-right">内 容：</label>
	                        <div class="col-sm-9">
	                            <textarea class="form-control" id="addcontent" name="content" rows="5" placeholder="内容" maxlength="500"></textarea>
	                        </div>
                   		</div>
					</div>
					</form>
					<div class="modal-footer">
						 <button type="button" class="btn btn-primary btn-sm" onclick="addUser();">保 存</button>
						<button type="button" class="btn btn-danger btn-sm" id="closeChangePasswordDialog" data-dismiss="modal">取 消</button>
					</div>
				</div>
			</div>
		</div>
		
			<!-- 修改 -->
		<div class="modal fade" id="userEdit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h5 class="modal-title">知识家修改</h5>
					</div>
                 <form class="form-horizontal"  action="${ctx }/knowledeUser/editInfo.html" id="editForm" method="post" enctype="multipart/form-data">
                 <input type="hidden" id="editId" name="id" />
					<div class="modal-body">
						<div class="form-group form-group-xs">
	                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>名 称：</label>
	                        <div class="col-sm-3 text-left">
	                            <input class="form-control" id="editknowledeName" name="knowledeName" value="" placeholder="名称" type="text">
	                        </div>
	                        <label for="name" class="col-sm-3 text-right"><span class="required">*</span>标 题：</label>
	                        <div class="col-sm-3 text-left">
	                            <input class="form-control" id="edittitle" name="title"  type="text" value="" maxlength="50"placeholder="标题">
	                        </div>
	                    </div>
	                    
	                    <div class="form-group form-group-xs">
	                        <label for="name" class="col-sm-2 text-right"><span class="required">*</span>是否置顶：</label>
	                        <div class="col-sm-3 text-left">
	                        <select class="form-control" id="editisTop" name="isTop">
	                        	<option value="0">否</option>
	                        	<option value="1">是</option>
	                        </select>
	                        </div>
	                        <label for="img" class="col-sm-3 text-right">图 片：</label>
	                        <div class="col-sm-3 text-left">
	                        <input type="file" class="form-control" name="img" id="img" />
	                        </div>
	                    </div>
	                    
	                    <div class="form-group form-group-xs">
	                        <label for="content" class="col-sm-2 text-right"><span class="required">*</span>内 容：</label>
	                        <div class="col-sm-9">
	                            <textarea class="form-control" id="editcontent" name="content" rows="5" placeholder="内容" maxlength="500"></textarea>
	                        </div>
                   		</div>
					</div>
					</form>
					<div class="modal-footer">
						 <button type="button" class="btn btn-primary btn-sm" onclick="editInfo();">保 存</button>
						<button type="button" class="btn btn-danger btn-sm" id="closeChangePasswordDialog" data-dismiss="modal">取 消</button>
					</div>
				</div>
			</div>
		</div>
		
		
		
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    function deleteUser(){
		 var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
		 if (rowIds.length < 1){
			 $.HN.message.alert("请选择要删除的用户！", "warn");
			 return;
		 }
	    	var list = [];
	    	for(var i = 0;i<rowIds.length;i++){
				list.push({"id":rowIds[i]});
			}
	    	$.HN.message.confirm("确定要删除所选知识家？", '', '').on(function (e) {
	            if (e) {
			$.post("${pageContext.request.contextPath}/knowledeUser/deleteUser.html", {
				"array" : json.jsonToString(list)
			}, function(result) {
				if (result.success) {
					$.HN.message.alert("删除成功！", "success");
					$("#gridlist").trigger("reloadGrid");
				} else {
					$.HN.message.alert("删除失败！", "error");
				}
			}, "json");
	            }
			});
	 }
    function editInfo(){
    	if ($("#editknowledeName").val().length < 1){
			 $.HN.message.alert("名称不能为空！", "warn");
			 return;
		 }
   	if ($("#edittitle").val().length < 1){
			 $.HN.message.alert("标题不能为空！", "warn");
			 return;
		 }
   	if ($("#editcontent").val().length < 1){
			 $.HN.message.alert("内容不能为空！", "warn");
			 return;
		 }
    	$.HN.message.confirm("确定要保存？", '', '').on(function (e) {
            if (e) {
         		$("#editForm").ajaxSubmit({
      			dataType : "json",
      			timeout: 10000,
      			success : function(result, statusText) {
      				if (result.success) {
      					    $('#userEdit').modal('hide');
      					    search( $("#gridlist").getGridParam("page"));
      					    top.$.HN.message.alert("修改成功！", "<spring:message code='message.HN.alert.type'/>", "success");
      				} else {
      					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
      				}
      			}
      		});
  		}
     	  });
    }
    function showEdit(id){
    	$('#editForm')[0].reset();
    	$.post("${pageContext.request.contextPath}/knowledeUser/getEditInfo.html", {
			"id" : id
		}, function(result) {
			$("#editId").val(id);
				$("#editknowledeName").val(result.rows.knowlede_name);
				$("#edittitle").val(result.rows.title);
				$("#editisTop").val(result.rows.is_top);
				$("#editcontent").html(result.rows.content);
				$('#userEdit').modal({
	                keyboard: true
	            });
		}, "json");
    }
    function addUser(){
    	if ($("#addknowledeName").val().length < 1){
			 $.HN.message.alert("名称不能为空！", "warn");
			 return;
		 }
    	if ($("#addtitle").val().length < 1){
			 $.HN.message.alert("标题不能为空！", "warn");
			 return;
		 }
    	if ($("#addcontent").val().length < 1){
			 $.HN.message.alert("内容不能为空！", "warn");
			 return;
		 }
    	$.HN.message.confirm("确定要保存？", '', '').on(function (e) {
            if (e) {
         		$("#addForm").ajaxSubmit({
      			dataType : "json",
      			timeout: 10000,
      			success : function(result, statusText) {
      				if (result.success) {
      					    $('#userAdd').modal('hide');
      					    search( $("#gridlist").getGridParam("page"));
      					    top.$.HN.message.alert("<spring:message code='message.HN.alert.success'/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code='message.HN.alert.type'/>", "success");
      				} else {
      					top.$.HN.message.alert(result.msg || "", "<spring:message code='message.HN.alert.type'/>", "error");
      				}
      			}
      		});
  		}
     	  });
    }
		 function showAddPage(){
			 $('#addForm')[0].reset();
			 $('#userAdd').modal({
	                keyboard: true
	            });
		 }
    	function search(page) {
    		var data = formatForm("form");
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:data,
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/knowledeUser/getKnowledeUserList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 250,
                colNames: ['操作','名称', '标题','内容', '是否置顶', '创建时间'],
                colModel: [
					{ name: 'id', width: 8, align:"left", sortable: false,formatter : function(val, opts, rowdata) {
				            var str = "<a href='#' onclick='showEdit(\""+val+"\")'>修改</a>";
	    	                return str;
	                    }},
					{ name: 'knowlede_name', width: 8, align:"left", sortable: false},
                    { name: 'title', width: 10, align:"left", sortable: false},
                    { name: 'content', width: 5, align:"center", sortable: false },
                    { name: 'is_top', width: 10, align: 'left', sortable: false},
                    { name: 'create_time', width: 10, align: 'left', sortable: false}
                ],
                rowNum: 20,
                rowList: [10, 20, 30],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "健康知识家列表",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                },
                jsonReader: {
                    id: "id"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
    </script>
</body>
</html>












